<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>限时秒杀</title>
</head>

<body>
    <div class="box">
        <div id="d" style="float: left;"></div>
        <div id="h" style="float: left;"></div>
        <div id="m" style="float: left;"></div>
        <div id="s" style="float: left;"></div>
    </div>

    <script>
        var endTime = new Date('2022-1-1 00:00:00'),
            endSeconds = endTime.getTime();
        var d = h = m = s = 0;
        var dDiv = document.getElementById('d');
        var hDiv = document.getElementById('h');
        var mDiv = document.getElementById('m');
        var sDiv = document.getElementById('s');
        var id = setInterval(seckill, 1000);

        function seckill() {
            var nowTime = new Date();
            var remaining = parseInt((endSeconds - nowTime.getTime()) / 1000);
            if (remaining > 0) {
                d = parseInt(remaining / 86400);
                h = parseInt((remaining / 3600) % 24);
                m = parseInt((remaining / 60) % 60);
                s = parseInt(remaining % 60);
            } else {
                clearInterval(id);
            }
            dDiv.innerHTML = (d < 10 ? '0' + d : d) + '天';
            hDiv.innerHTML = (h < 10 ? '0' + h : h) + '时';
            mDiv.innerHTML = (m < 10 ? '0' + m : m) + '分';
            sDiv.innerHTML = (s < 10 ? '0' + s : s) + '秒';
        }
    </script>
</body>

</html>